﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Globalization;

namespace PreProcessingLanguage
{
    class ProcessPragraph
    {

        private Ngram ng;
        private NgramSql ngs;
        private List<string> punctuation = new List<string>();
        private List<string> sentencesUS = new List<string>();
        private List<string> sentencesS = new List<string>();

        private static string PATTERN_PUNCTUATION = "[\n.,;“”:()!?'`\\\"/-] ?";

        public ProcessPragraph(Ngram ng)
        {
            this.ng = ng;
        }
        public ProcessPragraph(NgramSql ngs)
        {
            this.ngs = ngs;
        }

        private void splitSentence(string str)
        {
            MatchCollection mc = Regex.Matches(str, PATTERN_PUNCTUATION);
            foreach (Match m in mc)
            {
                punctuation.Add(m.Value);
            }
            foreach (string str1 in Regex.Split(str, PATTERN_PUNCTUATION))
            {
                sentencesUS.Add(str1);
            } 
        }
        public string process(string str)
        {
            string kq="";
            splitSentence(str.ToLower());
            foreach (string sen in sentencesUS)
            {
                Dictionary<string, double> t = ng.process(PreProcessing.ConvertToUnSign(sen));
                sentencesS.Add(ng.getKq(t));
            }
            if (sentencesS.Count > punctuation.Count)
            {
                for (int i = 0; i < punctuation.Count; i++)
                {
                    kq += sentencesS[i] + punctuation[i];
                }
                kq += sentencesS[sentencesS.Count - 1];
            }
            else
            {
                for (int i = 0; i < sentencesS.Count; i++)
                {
                    kq += sentencesS[i] + punctuation[i];
                }
            }
            sentencesUS.Clear();
            punctuation.Clear();
            sentencesS.Clear();
            return kq;
        }
        public string process2(string str)
        {
            string kq = "";
            splitSentence(str.ToLower());
            foreach (string sen in sentencesUS)
            {
                Dictionary<string, double> t = ngs.process(PreProcessing.ConvertToUnSign(sen));
                sentencesS.Add(ngs.getKq(t));
            }
            if (sentencesS.Count > punctuation.Count)
            {
                for (int i = 0; i < punctuation.Count; i++)
                {
                    kq += sentencesS[i] + punctuation[i];
                }
                kq += sentencesS[sentencesS.Count - 1];
            }
            else
            {
                for (int i = 0; i < sentencesS.Count; i++)
                {
                    kq += sentencesS[i] + punctuation[i];
                }
            }
            sentencesUS.Clear();
            punctuation.Clear();
            sentencesS.Clear();
            return kq;
        }

    }
}
